<!-- 门店仓位配置 -->
<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm">
      <el-form-item>
        <el-button icon="el-icon-plus" type="primary" @click="addOrUpdateHandle('','add')">新增</el-button>
      </el-form-item>
    </el-form>

    <div class="avue-crud">
      <el-table :data="dataList" border v-loading="dataListLoading">
          <el-table-column prop="deptName" label="门店名称"></el-table-column>
          <el-table-column label="销售仓位">
            <template><span>已配置</span></template>
          </el-table-column>
          <el-table-column label="退款仓位">
            <template><span>已配置</span></template>
          </el-table-column>
          <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row,'update')">配置</el-button>
            <el-button v-if="permissions.eimsstockconfig_del" type="text" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
  </div>
</template>

<script>
  import {fetchStockConfigDoneList,fetchStockConfigList, delStockConfigObj} from '@/api/eims/stock-config'
  import TableForm from './form'
  import {mapGetters} from 'vuex'
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 200,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false
      }
    },
    components: {
      TableForm
    },
    created () {
      this.getDataList()
    },
    computed: {
      ...mapGetters(['permissions'])
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        fetchStockConfigDoneList(Object.assign({
          current: this.pageIndex,
          size: this.pageSize
        })).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 新增 / 修改
      addOrUpdateHandle (data,type) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          let params ={
            deptId: data.deptId,
            deptName: data.deptName,
            type: type
          }
          this.$refs.addOrUpdate.init(params)
        })
      },
      // 删除
      deleteHandle (id) {
        this.$confirm('是否确认删除ID为' + id, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          return delStockConfigObj(id)
        }).then(response => {
          if(response.data.code == '0'){
            this.$message.success('删除成功')
            this.getDataList()
          }else{
            this.$message.error(response.data.msg)
          }
        })
      }
    }
  }
</script>
